package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    /**
     * 查询总记录数
     */
    @Select("select count(*) from emp")
    Long count();

    /**
     * 查询所有的员工及其对应的部门名称
     */

    List<Emp> selectPage(EmpQueryParam empQueryParam);

    @Select("select e.*, d.name deptName from emp  e left join dept  d on e.dept_id = d.id")
    Page<Emp> list();

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time,password) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime},#{password})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    @Select("select * from emp where id = #{id}")
    Emp selectById(Integer id);

    @MapKey("pos")
    List<Map<String, Object>> empJobDataMap();

    @Select("select if(gender=1, '男', '女') name, count(*) value from emp group by gender")
    List<Map<String, Object>> getEmpGenderData();

    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getUsernameAndPassword(Emp emp);

    void updateById(Emp emp);
}
